const CopyWebpackPlugin = require('copy-webpack-plugin')
//const path = require('path')
module.exports = {
    //baseUrl:'/springjwt/',
    //如果是生产环境就是./  如果是开发环境就是 /
    publicPath: process.env.NODE_ENV === 'production' ? './' : '/',
  
    outputDir: 'dist',
  
    assetsDir: 'static',
  
    filenameHashing: true,
  
    // When building in multi-pages mode, the webpack config will contain different plugins
    // (there will be multiple instances of html-webpack-plugin and preload-webpack-plugin).
    // Make sure to run vue inspect if you are trying to modify the options for those plugins.
    pages: {
      index: {
        // entry for the pages
        entry: 'src/main.js',
        // the source template
        template: 'src/pages/index/index.html',
        // output as dist/index.html
        filename: 'index.html',
        // when using title option,
        // template title tag needs to be <title><%= htmlWebpackPlugin.options.title %></title>
        title: '首页',
        // chunks to include on this pages, by default includes
        // extracted common chunks and vendor chunks.
        chunks: ['chunk-vendors', 'chunk-common', 'index']
      },
      ready: {
        // entry for the pages
        entry: 'src/pages/ready/ready.js',
        // the source template
        template: 'src/pages/ready/ready.html',
        // output as dist/index.html
        filename: 'ready.html',
        // when using title option,
        // template title tag needs to be <title><%= htmlWebpackPlugin.options.title %></title>
        title: '',
        // chunks to include on this pages, by default includes
        // extracted common chunks and vendor chunks.
        chunks: ['chunk-vendors', 'chunk-common', 'ready']
      },
      error: {
        // entry for the pages
        entry: 'src/pages/error/error.js',
        // the source template
        template: 'src/pages/error/error.html',
        // output as dist/index.html
        filename: 'error.html',
        // when using title option,
        // template title tag needs to be <title><%= htmlWebpackPlugin.options.title %></title>
        title: '异常错误',
        // chunks to include on this pages, by default includes
        // extracted common chunks and vendor chunks.
        chunks: ['chunk-vendors', 'chunk-common', 'error']
      },
      manager: {
        // entry for the pages
        entry: 'src/pages/manager/manager.js',
        // the source template
        template: 'src/pages/manager/manager.html',
        // output as dist/index.html
        filename: 'manager.html',
        // when using title option,
        // template title tag needs to be <title><%= htmlWebpackPlugin.options.title %></title>
        title: '后台管理',
        // chunks to include on this pages, by default includes
        // extracted common chunks and vendor chunks.
        chunks: ['chunk-vendors', 'chunk-common', 'manager']
      },
      testU: {
        // entry for the pages
        entry: 'src/pages/testU/testU.js',
        // the source template
        template: 'src/pages/testU/testU.html',
        // output as dist/index.html
        filename: 'testU.html',
        // when using title option,
        // template title tag needs to be <title><%= htmlWebpackPlugin.options.title %></title>
        title: '测试管理',
        // chunks to include on this pages, by default includes
        // extracted common chunks and vendor chunks.
        chunks: ['chunk-vendors', 'chunk-common', 'testU']
      }
      // when using the entry-only string format,
      // template is inferred to be `public/subpage.html`
      // and falls back to `public/index.html` if not found.
      // Output filename is inferred to be `subpage.html`.
      // subpage: ''
    },
    
    // when using the entry-only string format,
    // template is inferred to be `public/subpage.html`
    // and falls back to `public/index.html` if not found.
    // Output filename is inferred to be `subpage.html`.
    // subpage: ''
  
    // eslint-loader 是否在保存的时候检查
    lintOnSave: false,
  
    // 是否使用包含运行时编译器的Vue核心的构建
    runtimeCompiler: false,
  
    // 默认情况下 babel-loader 忽略其中的所有文件 node_modules
    transpileDependencies: [],
  
    // 生产环境 sourceMap
    productionSourceMap: false,
  
    // cors 相关 https://jakearchibald.com/2017/es-modules-in-browsers/#always-cors
    // corsUseCredentials: false,
    // webpack 配置，键值对象时会合并配置，为方法时会改写配置
    // https://cli.vuejs.org/guide/webpack.html#simple-configuration
    configureWebpack: (config) => {
      config.plugins.push(
        new CopyWebpackPlugin([{ from: 'WEB-INF/', to: 'WEB-INF' }]),
       )
    },
  
    // webpack 链接 API，用于生成和修改 webapck 配置
    // https://github.com/mozilla-neutrino/webpack-chain
    chainWebpack: (config) => {
      // 因为是多页面，所以取消 chunks，每个页面只对应一个单独的 JS / CSS
      config.optimization
        .splitChunks({
          cacheGroups: {}
        });
      // config.plugin('Copy')
      //   .tap(args => {
      //     //c[0] = {enable: true}
      //     args[0][0].from = 'E:\\vuespringjwt\\springbootjwt\\WEB-INF';
      //     args[0][0].to = 'WEB-INF';
      //     args[0][0].ignore = ['.*'];
      //     return args;
      //   });
      // 'src/lib' 目录下为外部库文件，不参与 eslint 检测
      //config.module
      //  .rule('eslint')
       // .exclude
      //  .add('/Users/maybexia/Downloads/FE/community_built-in/src/lib')
      //  .end()
    },
  
    // 配置高于chainWebpack中关于 css loader 的配置
    css: {
      // 是否开启支持 foo.module.css 样式
      modules: false,
  
      // 是否使用 css 分离插件 ExtractTextPlugin，采用独立样式文件载入，不采用 <style> 方式内联至 html 文件中
      extract: true,
  
      // 是否构建样式地图，false 将提高构建速度
      sourceMap: false,
  
      // css预设器配置项
      loaderOptions: {
        css: {
          // options here will be passed to css-loader
        },
  
        postcss: {
          // options here will be passed to postcss-loader
        }
      }
    },
  
    // All options for webpack-dev-server are supported
    // https://webpack.js.org/configuration/dev-server/
    devServer: {
      open: false,
  
      host: '127.0.0.1',
      //3000还是sso中心  是A系统
      port: 3000,
  
      https: false,
  
      hotOnly: false,
  
      
      
      // proxy:"http://xxxx.com",
      proxy: {
        '/api': {
          target: 'http://localhost:8878',
          //ws: false,
          changeOrigin: true, //是否允许跨域
          pathRewrite: {
            '^/api': '/', //重写
          }
        },
          '/sso': {
            target: 'http://www.sso.com',
            //ws: false,
            changeOrigin: true, //是否允许跨域
            pathRewrite: {
              '^/sso': '/', //重写
            }
        },
      }, // 配置多个代理
  
  
      before: app => {
      },
      disableHostCheck: true
    },
    // 构建时开启多进程处理 babel 编译
    parallel: require('os').cpus().length > 1,
  
    // https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-pwa
    pwa: {},
  
    // 第三方插件配置
    pluginOptions: {}
  };